<?php

// 本类由系统自动生成，仅供测试用途
class IndexAction extends BaseAction {

    public function index() {
        $this->display();
    }
    public function left(){
        $this->display();
    }
    public function main(){
        $this->display();
    }

    public function login() {
        $err = $this->_param("err");
        switch ($err) {
            case 1 : $errstring = "验证码错误";
                break;
            case 2 : $errstring = "管理员账号或密码有误";
                break;
            default : $errstring = "";
        }
        $this->assign("err", $errstring);
        $this->display();
    }

    public function login_do() {
        $param_name = $this->_param('name');
        $param_password = $this->_param('pwd');
        $param_verify = $this->_param('verify');
        if (md5($param_verify) != $_SESSION['verify']) {
            $this->redirect("login", array("err" => "1"));
        }
        $user = M("Users");
        $result = $user->where("(name='{$param_name}' or phone='{$param_name}') and pwd='" . md5($param_password) . "'")->select();
        if ($result && $param_name == 'dandancat') {
            $_SESSION['userid'] = $result[0]['id'];
            $_SESSION['name'] = $result[0]['name'];
            $_SESSION['phone'] = $result[0]['phone'];
            $_SESSION['qq'] = $result[0]['qq'];
            $_SESSION['type'] = $result[0]['type'];
            $_SESSION['money'] = $result[0]['money'];
            $this->redirect("index");
        } else {
            $this->redirect("login", array("err" => "2"));
        }
    }

}